package com.atguigu.spring.config;

import com.atguigu.spring.bean.Cat;
import com.atguigu.spring.bean.Person;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.*;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author mi
 * @time 2021/3/7 8:55
 */
//@Import({ MainConfig.MyImportBeanDefinitionRegistrar.class})
@Configuration  // 定义配置类
@ComponentScan("com.atguigu.spring")  // 配置包扫描路径 包扫描引入注解(例如@Component)定义的组件
public class MainConfig {
	public MainConfig() {
		System.out.println("MainConfig 主配置类创建...");
	}
//	@Bean
//	public Person createPerson(){
//		Person person = new Person();
//		return person;
//	}



	static class  MyImportBeanDefinitionRegistrar  implements   ImportBeanDefinitionRegistrar{

		@Override
		public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
			String beanName = "jiaojiao";
			RootBeanDefinition beanDefinition = new RootBeanDefinition();
			beanDefinition.setBeanClass(Cat.class);
			registry.registerBeanDefinition(beanName,beanDefinition);
		}
	}
}
